package com.lry.jvm.classfile.attributes;

import com.lry.jvm.classfile.ClassReader;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
@Data
public class LocalVariableTypeTable implements AttributeInfo {

    private int localVariableTypeTableLen;

    private LocalVariableTable[] localVariableTables;

    @Override
    public void readInfo(ClassReader reader) {
        localVariableTypeTableLen = reader.nextU2ToInt();
        localVariableTables = new LocalVariableTable[localVariableTypeTableLen];

        for(int i=0;i<localVariableTypeTableLen;i++){
            localVariableTables[i] = readLocalVariableTable(reader);
        }
    }

    private LocalVariableTable readLocalVariableTable(ClassReader reader){
        LocalVariableTable localVariableTable = new LocalVariableTable();
        localVariableTable.setStartPc(reader.nextU2ToInt());
        localVariableTable.setLength(reader.nextU2ToInt());
        localVariableTable.setNameIndex(reader.nextU2ToInt());
        localVariableTable.setSignatureIndex(reader.nextU2ToInt());
        localVariableTable.setIndex(reader.nextU2ToInt());
        return localVariableTable;
    }

    @Setter
    @Getter
    class LocalVariableTable {
        private int startPc;

        private int length;

        private int nameIndex;

        private int signatureIndex;

        private int index;
    }
}
